#pragma once

#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

using namespace std;

class InetAddr
{
private:
    void getaddress(string* ip,uint16_t* port)
    {
        *port = ntohs(_addr.sin_port);
        *ip = inet_ntoa(_addr.sin_addr);
    }
public:
    InetAddr(const sockaddr_in& addr)
    :_addr(addr)
    {
        getaddress(&_ip,&_port);
    }

    bool operator==(const InetAddr &addr)
    {
        if(_ip == addr._ip && _port == addr._port)
        {
            return true;
        }
        return false;
    }

    sockaddr_in Addr()
    {
        return _addr;
    }

    string ip()
    {
        return _ip;
    }

    uint16_t port()
    {
        return _port;
    }

    ~InetAddr()
    {
    }

private:
    sockaddr_in _addr;
    string _ip;
    uint16_t _port;
};




